﻿<Window x:Class="SellAvi.Views.WindowProductList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        xmlns:converters="clr-namespace:SellAvi.Views.Converters"
        Title="Каталог продукции для размещения на Avito" Height="600" Width="850"
        DataContext="{Binding MultipleProducts, Source={StaticResource Locator}}">
    <Window.Resources>
        <converters:StringToVisibilityConverter x:Key="svc" />
    </Window.Resources>
    <DockPanel>
        <ToolBarTray DockPanel.Dock="Top" Background="White">
            <ToolBar Band="0" BandIndex="0">
                <Button ToolTip="Поставить товар в очередь на загрузку в Avito" Command="{Binding MarkProductsCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/flag.png" />
                        <TextBlock Margin="5,0,5,0" FontWeight="DemiBold">Опубликовать</TextBlock>
                    </StackPanel>
                </Button>
                <Button ToolTip="Добавить новый продукт" Command="{Binding AddNewProductCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/edit.png" />
                        <TextBlock Margin="5,0,5,0">Редактировать</TextBlock>
                    </StackPanel>
                </Button>
                <Button ToolTip="Удалить выделенные продукты" Command="{Binding DeleteSelectedProductsCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/trash.png" />
                        <TextBlock Margin="5,0,5,0">Удалить</TextBlock>
                    </StackPanel>
                </Button>
                <Button ToolTip="Импортировать объявления из Файла" Command="{Binding ImportProductsCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/download.png" />
                        <TextBlock Margin="5,0,5,0">Импорт</TextBlock>
                    </StackPanel>
                </Button>
                <Button ToolTip="Экспортировать товары в Excel" Command="{Binding ExportToExcelCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/excel.png" />
                        <TextBlock Margin="5,0,5,0">В Excel</TextBlock>
                    </StackPanel>
                </Button>
            </ToolBar>
            <ToolBar Band="0" BandIndex="1">
                <ToggleButton ToolTip="Показывать товары всех пользователей" Command="{Binding FilterProductsCommand}" CommandParameter="ApplyUserFilter">
                    <Image Source="/Resources/manman.png" />
                </ToggleButton>
                <ToggleButton  ToolTip="Показывать только опубликованные товары" Command="{Binding FilterProductsCommand}" CommandParameter="ApplyPublishedFilter">
                    <Image Source="/Resources/cart.png" />
                </ToggleButton>
            </ToolBar>
        </ToolBarTray>
        <!--<ScrollViewer VerticalScrollBarVisibility="Auto">-->
        <!--SelectedItems="{Binding CheckedAvitoProducts}"-->
        <DataGrid ItemsSource="{Binding AvitoProducts}" x:Name="ProductsDataGrid" CanUserAddRows="False"
                      CanUserReorderColumns="True" CanUserResizeColumns="True"
                      CanUserResizeRows="False" CanUserSortColumns="True"
                      IsReadOnly="True"
                      RowHeight="18"
                      AlternatingRowBackground="WhiteSmoke" VerticalGridLinesBrush="Lavender" HorizontalGridLinesBrush="White" AlternationCount="2" AutoGenerateColumns="False">
            <DataGrid.InputBindings>
                <KeyBinding Key="Delete" Command="{Binding DeleteSelectedProductsCommand}" />
            </DataGrid.InputBindings>
            <!-- * Убираем границу при наводе фокуса на строку * -->
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                </Style>
            </DataGrid.CellStyle>
            
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <command:EventToCommand
                Command="{Binding ProductsSelectionChangedCommand}"
                CommandParameter="{Binding SelectedItems, ElementName=ProductsDataGrid}" />
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <command:EventToCommand Command="{Binding EditProductCommand}"
                                CommandParameter="{Binding ElementName=ProductsDataGrid, Path=SelectedItem}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <Grid>
                        <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay,
                  RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}}"/>
                    </Grid>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>
            <!--Описание колонок-->
            <DataGrid.Columns>
                <DataGridTextColumn Width="Auto" Header="Id" Binding="{Binding Id}" />
                <DataGridTextColumn Width="80" Header="Категория" Binding="{Binding Category.ShortCategoryName}" />
                <DataGridTextColumn Width="*" Header="Заголовок" Binding="{Binding Title}" />
                <DataGridTextColumn Width="2*" Header="Описание" Binding="{Binding Description}"/>
                <DataGridTextColumn Width="60" Header="Цена" Binding="{Binding Price}"/>
                <DataGridTextColumn Width="95" Header="Телефон" Binding="{Binding ParsedPhone}"/>
                <DataGridTemplateColumn Width="20">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <!-- http://stackoverflow.com/questions/15526715/wpf-mvvm-command-data-context-issue -->
                            <Button DataContext="{Binding}" Visibility="{Binding Path=PostedOnUrl, Converter={StaticResource svc}, Mode=OneWay}"
                                    Command="{Binding ElementName=ProductsDataGrid, Path=DataContext.BrowseProductCommand}"
                                    CommandParameter="{Binding ElementName=ProductsDataGrid, Path=SelectedItem}" >
                                <Image Height="12" Source="/SellAvi;component/Resources/cart.png"></Image>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>

            <!--<DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <Image Height="100" Source="{Binding Image}" />
                    </DataTemplate>
                </DataGrid.RowDetailsTemplate>-->
        </DataGrid>

        <!--</ScrollViewer>-->
    </DockPanel>
</Window>
